package com.hopu.v1.controller.front.exam;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.exam.ExamRecords;
import com.hopu.v1.service.front.exam.ExamService;
import com.hopu.v1.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: ExamRecordsController
 * Description:
 *
 * @Author lh
 * @Create 2024/9/26 19:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private ExamService examRecordsService;

    /**
     * 查询用户下的考试
     * @param id
     * @return
     */
    @GetMapping("/selectStudentExam")
    public R selectStudentExam(Page<ExamRecords> page, Integer id,HttpServletRequest request) {
        String token = request.getHeader("frontToken");
        String studentId = JwtUtils.getUserId(token);
        System.out.println("studentId"+studentId);
        return R.ok(examRecordsService.selectStudentExam(page,id,studentId));
    }

    /**
     * 查询某个试卷信息及题目&选项
     * @param recordsId
     * @return
     */
    @GetMapping("/getExam")
    public R getQuestionsList(Integer recordsId,HttpServletRequest request) {
        String token = request.getHeader("frontToken");
        String studentId = JwtUtils.getUserId(token);
        System.out.println("studentId"+studentId);
        return R.ok(examRecordsService.getStudentOneExam(recordsId,studentId));
    }

}
